

#delimit;

/* Use OFAC Enforcement Data */

use "C:\Users\bapat\Desktop\sanctionsps\US Sanctions OFAC Enforcement Data - 2003 - 2018.dta";
gen iranfin=0;
replace iranfin=1 if Iran6==1;
replace iranfin=0 if FinServ==0;
collapse (sum) iranfin, by(year month);
sort year month;

gen iranfin1=0;
replace iranfin1=1 if iranfin>0;

sort year month;

/* Merge Data on Oil and Gold Prices */ 

save "C:\Users\bapat\Desktop\sanctionsps\rep11.dta", replace;

merge year month using  "C:\Users\bapat\Desktop\sanctionsps\rep2_goldoilI.dta";

sort year month;
drop _merge;

/* Merge Data on Dollar Index */

merge year month using  "C:\Users\bapat\Desktop\sanctionsps\rep3_dollarindex.dta";
drop _merge;
sort year month;

/* Merge Data on Iraq war from Iraq Body Count */

merge year month using  "C:\Users\bapat\Desktop\sanctionsps\iraqbodycount.dta"; 


drop _merge;
sort year month;


save "C:\Users\bapat\Desktop\sanctionsps\rep11.dta", replace;

clear;

/* Merge data from Militarized Interstate Dispute Dataset */

use "C:\Users\bapat\Desktop\sanctionsps\rep_mid.dta";

keep if ccode==630;

drop if styear<2003;

drop if sidea==0;

rename styear year;
rename stmon month;

gen mid=1;
collapse (sum) mid, by (year month);
sort year month;
save "C:\Users\bapat\Desktop\iranmid.dta", replace;

clear;

use "C:\Users\bapat\Desktop\sanctionsps\rep11.dta", ;

sort year month;
merge year month using "C:\Users\bapat\Desktop\iranmid.dta";
drop _merge;
sort year month;

replace iranfin=0 if iranfin==.;
replace iranfin1=0 if iranfin1==.;

sort year month;
replace mid=0 if mid==.;
replace mid=. if year>2014;

/*Begin setting up data for duration analysis */ 

duplicates drop;

gen counter=.;
move counter inflationrate;
replace counter=1 if iranfin1[_n-1]==1;
replace counter=counter[_n-1]+1 if counter==.;

rename counter duration;
drop if duration==.;
stset duration, failure(iranfin1==1);


save "C:\Users\bapat\Desktop\sanctionsps\rep11.dta", replace;


/*Plot Distribution to demonstrate */ 

hist duration;
graph save "Graph" "C:\Users\bapat\Desktop\sanctionsps\iranfndist.gph", replace;

/* Lag independent variables by one year */ 

gen dollarindexlag=dollarindex[_n-1];
gen EURUSDlag = EURUSD[_n-1];
gen loggold = ln(goldpricelondon);
gen goldlag=loggold[_n-1];
gen inflationlag=inflationrate[_n-1];
gen iraqincidentlag=iraqincident[_n-1];
gen midlag=mid[_n-1];
gen wtioillag=wtioil[_n-1];
gen iranfinlag = iranfin[_n-1];
gen mid1=0;
replace mid1=1 if mid>0;
replace mid1=. if mid==.;
gen reform=0;
replace reform=1 if year>2008 & year<2017;

/* Descriptive Statistics */

summarize goldpricelondon dollarindex EURUSD wtioil inflationrate mid1 reform iraqincident;
tab mid1;
tab reform;

/* Weibull Analysis */

streg c.goldlag c.inflationrate  i.mid1 c.iraqincident i.reform, dist(w) robust nolog nohr ;

margins, at(goldlag=(5.9(.1)7.3));

stcurve, hazard at(goldlag=(6.4 6.8 7.2));

graph save "Graph" "C:\Users\bapat\Desktop\sanctionsps\Gold1.gph", replace;

/*Cox Analysis */ 

stcox c.goldlag c.inflationrate  i.mid1 c.iraqincident i.reform, efron robust nolog;

/*Appendix */

/*Robustness Checks */

streg c.goldlag , dist(w) robust nolog nohr ;

streg c.goldlag c.inflationrate , dist(w) robust nolog nohr ;

streg c.goldlag i.mid1 , dist(w) robust nolog nohr ;

streg c.goldlag c.iraqincident, dist(w) robust nolog nohr ;

streg c.goldlag  i.reform, dist(w) robust nolog nohr ;

/* Alternative Measures */ 

streg c.dollarindexlag c.inflationrate i.mid1 c.iraqincident i.reform, dist(w) robust nolog  ;

margins, at(dollarindex=(75(2.5)100));

stcurve, hazard at(dollarindexlag=(78 86 94));

graph save "Graph" "C:\Users\bapat\Desktop\sanctionsps\USD.gph", replace;

streg c.EURUSDlag c.inflationrate  i.mid1 c.iraqincident i.reform, dist(w) robust nolog nohr ;

margins, at(EURUSD=(1.05(.05)1.55));

stcurve, hazard at(EURUSD=(1.17 1.29 1.41));

graph save "Graph" "C:\Users\bapat\Desktop\sanctionsps\EURUSD1.gph", replace;

stcox c.EURUSDlag c.inflationrate i.mid1 c.iraqincident i.reform, efron robust nolog nohr;

streg c.wtioillag c.inflationrate  i.mid1 c.iraqincident i.reform, dist(w) robust nolog nohr ;

margins, at(wtioillag=(30(5)130));

stcurve, hazard at(wtioillag=(45 69 93));

graph save "Graph" "C:\Users\bapat\Desktop\sanctionsps\Oil1.gph", replace;

stcox c.wtioillag c.inflationrate  i.mid1 c.iraqincident i.reform, efron robust nolog nohr;

graph combine "C:\Users\bapat\Desktop\sanctionsps\USD.gph" "C:\Users\bapat\Desktop\sanctionsps\EURUSD1.gph" "C:\Users\bapat\Desktop\sanctionsps\Oil1.gph";



